var Main = {
    data() {
        return {
            ruleForm: {
                Username: '',
                Password: ''
            },
            rules: {
                Username: [
                    { required: true, message: '请输入账号', trigger: 'blur' },
                    { min: 2, message: '长度不能少于 2 个字符', trigger: 'blur' }
                ],
                Password: [
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    { min: 6, message: '长度不能少于 6 个字符', trigger: 'blur' }
                ],
            }
        };
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (!valid) {
                    return
                }
                let _this = this
                axios.post('auth', _this.ruleForm)
                    .then(res => {
                        console.log(res.data)
                        if (res.data.code === 200) {
                            this.$message({
                                showClose: true,
                                message: '登录成功',
                                type: 'success'
                            })
                            storage['token'] = res.data.token
                            location.href = res.data.url
                        } else {
                            this.$message({
                                showClose: true,
                                message: '登录失败',
                                type: 'error'
                            })
                        }
                    })
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        }
    }
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')